/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Laurent Berthelot
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.display.screen
{
	import flash.geom.Point;

	/**
	 * SizeProps class used by the ScreenManager class to define size of objects on screen
	 * @author	Laurent Berthelot
	 */
	public class SizeProps extends Object
	{	
		//--------------------------------------------------------------------------
		//
		//  Public vars
		//
		//--------------------------------------------------------------------------
		/**
		 * Indicates if the object must be resized to the specified percent, or if the width and height properties must be used as references
		 */
		public var resize:Boolean;
		public var width:Number;
		public var height:Number;
		
		
		//--------------------------------------------------------------------------
		//
		//  Private vars
		//
		//--------------------------------------------------------------------------
		/**
		 * @private
		 */
		protected var _width:Number;
		/**
		 * @private
		 */
		protected var _height:Number;		
		/**
		 * @private
		 */
		protected var _widthIsPercent:Boolean = false;
		/**
		 * @private
		 */
		protected var _heightIsPercent:Boolean = false;
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Constructs a new SizeProps instance. If wPrecent and hPercent are false, the object will not be resized but the specified width and height will be used to position it on screen.
		 * @param	width		The width of the object, in pixels or in precent [0->1]
		 * @param	height		The height of the object, in pixels or in precent [0->1]
		 * @param	wPercent	Indicates if the object must be resized to a percent width (true) or if the width property must be used as a reference in pixels
		 * @param	hPercent	Indicates if the object must be resized to a percent height (true) or if the height property must be used as a reference in pixels
		 */
		public function SizeProps(width:Number = 0, height:Number = 0, wPercent:Boolean = true, hPercent:Boolean = true) {
			_width = width;
			_widthIsPercent = wPercent;
			_height = height;
			_heightIsPercent = hPercent;
			this.resize = wPercent || hPercent;
			updateProperties();
		}
		
		/**
		 * Updates width and height values.
		 * @param	wRef	the reference width container, generally the stage.stageWidth
		 * @param	hRef    the reference height container, generally the stage.stageHeight
		 */
		public function updateProperties(wRef:Number = 0, hRef:Number = 0):void {
			width = _updateProperty(_width, wRef, _widthIsPercent);
			height = _updateProperty(_height, hRef, _heightIsPercent);
		}
		
		/**
		 * Returns the string representation of the specified object.
		 */
		public function toString():String {
			return "[SizeProps width : " + _width + " - height " + _height + "]";
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Private methods
		//
		//--------------------------------------------------------------------------
		private function _updateProperty(value:Number, referer:Number = 0, isPercent:Boolean = false):Number {
			return isPercent ? value * referer : value;
		}
	}
}